package joke.deal;

import joke.ibatis.dao.ComicDao;
import joke.ibatis.dao.WeightDao;
import joke.ibatis.po.ComicPO;
import joke.ibatis.po.ParameterPo;
import joke.ibatis.po.WeightPo;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ReComic {
	public ComicPO viewComicByOrder(ParameterPo parpo) {
		ApplicationContext factory = new ClassPathXmlApplicationContext(
				"applicationContext.xml");// 初始化配置文件
		ComicDao cdao = (ComicDao) factory.getBean("comicDao");// 获取pageLinkDao对象
		ComicPO po = cdao.getComicPOOrder(parpo);
		return po;

	}
	
	public ComicPO viewComicByRandom() {
		ApplicationContext factory = new ClassPathXmlApplicationContext(
				"applicationContext.xml");// 初始化配置文件
		ComicDao cdao = (ComicDao) factory.getBean("comicDao");// 获取pageLinkDao对象
		ComicPO po = cdao.getContentByRandom("");
		WeightDao wdao = (WeightDao) factory.getBean("weightDao");// 获取pageLinkDao对象
		WeightPo wpo = wdao.getWeightPo("comic");
		po.setWpo(wpo);
		return po;

	}

	public byte[] getImage(String id) {
		ApplicationContext factory = new ClassPathXmlApplicationContext(
				"applicationContext.xml");// 初始化配置文件
		ComicDao cdao = (ComicDao) factory.getBean("comicDao");// 获取ImageDao对象
		try {
			ComicPO po = new ComicPO();
			po.setId(id);
			po = cdao.getComicPoById(po);
			return po.getMagic();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
